package com.well.menjin.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.well.menjin.dao.IDoorcontrDao;
import com.well.menjin.domain.Doorcontr;
import com.well.menjin.model.DoorcontrOpt;
import com.well.menjin.model.Sort;
import com.well.menjin.service.IDoorcontrService;

/**
 * 
* @ClassName: DoorcontrServiceImpl 
* @Description: 控制器实现业务层
* @author 姜俊健 
* @date 2016年6月28日 下午2:49:15 
*
 */
@Service
@Transactional
public class DoorcontrServiceImpl implements IDoorcontrService{
	@Autowired
	private IDoorcontrDao doorcontrdao ;
	
	@Override
	public List<Doorcontr> getDoorcontrs(int start,int limit,int page,List<Sort> sorto,String controller_id,
			String controller_name,String ip_address) {
		List<Doorcontr> doorcontrs = doorcontrdao.getDoorcontrs(start,limit,page,sorto,controller_id,
				controller_name,ip_address);
		return doorcontrs;
	}
	
	@Override
	public int getDoorcontrsCount( String controller_id,String controller_name, String ip_address) {
		List<Doorcontr> doorcontrs = doorcontrdao.getDoorcontrsCount(controller_id,controller_name,ip_address);
		return doorcontrs.size();
	}

	@Override
	public boolean isExist(String controller_id) {		
		return doorcontrdao.isExist(controller_id);
	}

	@Override
	public boolean addDoorcontr(Doorcontr doorcontr) {
		doorcontr.setCreate_date(new Timestamp(System.currentTimeMillis()));
		doorcontrdao.addDoorcontr(doorcontr);
		return true;
	}

	@Override
	public boolean updateDoorcontr(Doorcontr doorcontr) {
		doorcontr.setUpdata_date(new Timestamp(System.currentTimeMillis()));
		doorcontrdao.updateDoorcontr(doorcontr);
		return true;
	}

	@Override
	public List<DoorcontrOpt> getDoorcontrOpts() {
		List<Doorcontr> doorcontrs = doorcontrdao.getDoorcontrOpts();
		List<DoorcontrOpt> results = new ArrayList<>();
		for(Doorcontr doorcontr:doorcontrs){
			DoorcontrOpt doorcontrOpt = new DoorcontrOpt();
			doorcontrOpt.setController_id(doorcontr.getController_id());
			doorcontrOpt.setController_name(doorcontr.getController_name());
			results.add(doorcontrOpt);
		}
		return results;
	}







}
